package com.ndp.fb.mq.consumer.business;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ndp.fb.constant.ConfigConst;
import com.ndp.fb.model.fbagent.param.ApiCallBackTarget;
import com.ndp.fb.mq.api.service.schedulerservice.business.AdSetUpdateService;
import com.ndp.fb.mq.consumer.AbstractPullConsumer;
import com.ndp.fb.mq.consumer.business.syncbusiness.AdGroupGCBusiness;

/**
 * Created by Elvis.Xiong on 2015/3/6.
 */
@Component
public class AdGroupConsumerServiceImpl extends AbstractPullConsumer {

    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    AdGroupGCBusiness adGroupGCBusiness;

    @Autowired
    private AdSetUpdateService adSetUpdateService;

    @Override
    protected void consume(String tag, String keys, Object message, Map<String, String> equipment) {
        logger.debug("AdGroupConsumerServiceImpl tag >>>> " + tag + " keys >>>" + keys + " message >>> " + message);
        ApiCallBackTarget.Business target = (ApiCallBackTarget.Business) ApiCallBackTarget.getTargetType(tag);
        switch (target) {
            case DeleteAdGroupByBoss:
                adGroupGCBusiness.deleteAdFromBoss(equipment);
                break;
            case GcAdGroupByBoss:
                adGroupGCBusiness.gcAdFromBoss(message);
                break;
            case GcAdGroupCallback:
                adGroupGCBusiness.gcAdFromBossCallback(message);
                break;
            case UpdateASet:
                adSetUpdateService.updateBidInfo(equipment, message);
                break;
            default:
                logger.warn("不识别的消息tag >>>>" + tag + " ; message >>> " + message);
        }
    }

    @Override
    public String getTopicName() {
        return ConfigConst.MQ_SERVICES_BUESINESS_TOPIC;
    }
}
